<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>图片上传</title>
</head>

<body>
  <input type="file" class="update">
  <img src="" alt="" class="img"></img>
  <script src="http://cdn.jsdelivr.net/npm/axios@0.21.1/dist/axios.min.js">
  </script>
  <script>
    const update = document.querySelector('.update')
    update.addEventListener('change', e => {
      const file = e.target.files[0]
      const formData = new FormData()
      formData.append('file', file)
      axios({
        url: 'http://hmajax.itheima.net/api/upload',
        method: 'post',
        data: formData
      }).then(res => {
        console.log(res)
        console.log(res.data.data.url)
        document.querySelector('.img').src = res.data.data.url
      })
    })
  </script>

</body>

</html>